<!-- 管道管理页面 -->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="管道类型">
              <j-dict-select-tag placeholder="请选择管道类型" v-model="queryParam.pipType" dictCode="ps_pip_type" />
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="管道缺陷">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.pipDefective"
                dictCode="ps_pip_defective"
                placeholder="请选择管道缺陷"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="起点点位">
              <a-input placeholder="请输入起始管点编号" v-model="queryParam.pipPointSt"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="终点点位">
              <a-input placeholder="请输入终点管点编号" v-model="queryParam.pipPointEd"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="管道级别">
              <a-select v-model="queryParam.pipLevel" placeholder="请选择管道级别">
                <a-select-option :value="undefined">请选择</a-select-option>
                <a-select-option :value="1">1级</a-select-option>
                <a-select-option :value="2">2级</a-select-option>
                <a-select-option :value="3">3级</a-select-option>
                <a-select-option :value="4">4级</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属区域">
              <j-select-depart placeholder="请选择区域" v-model="queryParam.areaId" />
            </a-form-item>
          </a-col> -->
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search" style="margin: 0 auto 10px">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin: 0 0 10px 8px">重置</a-button>
              <a v-show="false" @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importProgressExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入工程进度</a-button>
      </a-upload> -->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" -->
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="pipDefectiveSlot" slot-scope="text">
          <div>{{ text | filterPipDefective(pipDefectiveList) }}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <paishui-pip-modal ref="modalForm" @ok="modalFormOk"></paishui-pip-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { pipLevel } from '@/config/enumeration.js'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import PaishuiPipModal from '@views/modules/PaishuiPip/PaishuiPipModal'

import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil'
import { getDictItemListByCode } from '@/api/system.js'
export default {
  name: 'PaishuiPipList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    PaishuiPipModal,
  },
  filters: {
    filterPipDefective(val, list) {
      const item = list.find((item) => item.value === '' + val)
      if (item) {
        return item.label
      } else {
        return val || '--'
      }
    },
  },
  data() {
    return {
      description: '管道管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (t, r, index) => {
            const { pageSize, current } = this.ipagination
            return (current - 1) * pageSize + parseInt(index) + 1
          },
        },
        // {
        //   title: '所属区域',
        //   align: 'center',
        //   dataIndex: 'areaId_dictText',
        // },
        {
          title: '起点点位',
          align: 'center',
          dataIndex: 'pipPointSt',
        },
        {
          title: '终点点位',
          align: 'center',
          dataIndex: 'pipPointEd',
        },
        {
          title: '管道级别',
          align: 'center',
          dataIndex: 'pipLevel',
          customRender: (t, r, index) => {
            const pipLevelItem = pipLevel.find((item) => item.value === t)
            return pipLevelItem ? pipLevelItem.label : '--'
          },
        },
        {
          title: '材质',
          align: 'center',
          dataIndex: 'pipMaterial_dictText',
        },
        {
          title: '管道类型',
          align: 'center',
          dataIndex: 'pipType_dictText',
        },
        {
          title: '是否清淤',
          align: 'center',
          dataIndex: 'isDredging',
          customRender: (t, r, index) => {
            return t == 2 ? '是' : '否'
          },
        },
        {
          title: '管道缺陷',
          align: 'center',
          dataIndex: 'pipDefective',
          scopedSlots: { customRender: 'pipDefectiveSlot' },
        },
        {
          title: '管径',
          align: 'center',
          dataIndex: 'pipDiameter_dictText',
        },
        {
          title: '起点埋深',
          align: 'center',
          dataIndex: 'burialDepthSt',
        },
        {
          title: '终点埋深',
          align: 'center',
          dataIndex: 'burialDepthEd',
        },
        {
          title: '管道缺陷',
          align: 'center',
          dataIndex: 'pipDefective',
          customRender: (text) => {
            return filterDictTextByCache('nw_terminal_material', text)
          },
        },
        {
          title: '管道长度',
          align: 'center',
          dataIndex: 'hieght',
        },
        {
          title: '所属处理厂/水系', //new
          align: 'center',
          dataIndex: 'facilityId',
        },
        // {
        //   title:'埋设方式',
        //   align:"center",
        //   dataIndex: 'embeddingMethod_dictText'
        // },
        // {
        //   title: '状态',
        //   align: 'center',
        //   dataIndex: 'status_dictText',
        //   customRender: (t) => {
        //     return t ? t : '--'
        //   },
        // },
        // {
        //   title:'备注',
        //   align:"center",
        //   dataIndex: 'remark'
        // },
        // {
        //   title:'是否生效 0生效 1失效',
        //   align:"center",
        //   dataIndex: 'effective'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/paishui/paishuiPip/list',
        delete: '/paishui/paishuiPip/delete',
        deleteBatch: '/paishui/paishuiPip/deleteBatch',
        exportXlsUrl: '/paishui/paishuiPip/exportXls',
        importExcelUrl: 'paishui/paishuiPip/treeImport',
        importProgressExcelUrl: 'paishui/geophysical/treeImport',
      },
      dictOptions: {},
      superFieldList: [],
      pipDefectiveList: [],
    }
  },
  created() {
    this.getSuperFieldList()
    this.handleGetDictItemList('ps_pip_defective')
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    importProgressExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importProgressExcelUrl}`
    },
  },
  methods: {
    async handleGetDictItemList(dictCode) {
      const res = await getDictItemListByCode({ dictCode })
      this.pipDefectiveList = (res.result || []).map((x) => {
        return {
          name: x.itemText,
          label: x.itemText,
          value: x.itemValue,
        }
      })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'pipPointSt', text: '开始管点编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'pipPointEd', text: '终点管点编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'pipType', text: '管道类型', dictCode: 'ps_pip_type' })
      fieldList.push({ type: 'int', value: 'pipLevel', text: '管道级别', dictCode: 'pipLevel' })
      fieldList.push({ type: 'int', value: 'isDredging', text: '是否清淤', dictCode: 'isDredging' })
      fieldList.push({ type: 'int', value: 'pipDefective', text: '管道缺陷', dictCode: 'ps_pip_defective' })
      fieldList.push({ type: 'int', value: 'pipMaterial', text: '材质', dictCode: 'ps_pip_material' })
      fieldList.push({ type: 'string', value: 'areaId', text: '区域id', dictCode: 'paishui_area,area_name,id' })
      fieldList.push({ type: 'BigDecimal', value: 'burialDepthSt', text: '起点埋深', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'burialDepthEd', text: '终点埋深', dictCode: '' })
      fieldList.push({ type: 'int', value: 'pipDiameter_dictText', text: '管径', dictCode: '' })
      fieldList.push({ type: 'double', value: 'hieght', text: '长度', dictCode: '' })
      fieldList.push({ type: 'int', value: 'embeddingMethod', text: '埋设方式', dictCode: 'ps_ms_type' })
      fieldList.push({ type: 'int', value: 'status', text: '状态', dictCode: 'ps_pip_status' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'effective', text: '是否生效 0生效 1失效', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
